/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package client;
import entreprise.UserPatient;
import java.util.ArrayList;
import mapping.DBUserPatient;

/**
 *
 * @author duonghau
 */
public class UserPatientBean {
    String patientID="";
    String userName="";
    String userPass="";    
    String message="";
    String styleMessage="";
    boolean loginStatus=false;
    DBUserPatient dBUserPatient;
    
    
    public String getPatientID() {
        return patientID;
    }

    public void setPatientID(String patientID) {
        this.patientID = patientID;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPass() {
        return userPass;
    }

    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }

    public String getMessage() {
        return message;
    }

    public String getStyleMessage() {
        return styleMessage;
    }   

    public boolean isLoginStatus() {
        return loginStatus;
    }

    public void setLoginStatus(boolean loginStatus) {
        this.loginStatus = loginStatus;
    }    
    
    public String login(){
        dBUserPatient=new DBUserPatient();
        UserPatient userPatient=dBUserPatient.getUser(userName);
        if(userPatient!=null){
            if(userPatient.getUserPass().equals(userPass)){
                patientID=userPatient.getPatientID();
                loginStatus=true;
                message="Login success";
                styleMessage="success";
                return "index";
            }else{
                message="User name or password incorrec.";
                styleMessage="error";  
                loginStatus=false;
                return "login";
            }            
        }else{
            message="User name or password incorrec.";
            styleMessage="error";    
            loginStatus=false;
            return "login";
        }
    }
}
